<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="0.8.1" basedir="." default="build-all">

    <description>Builds the module suite 0.8.</description>
    <import file="nbproject/build-impl.xml"/>

    <echo message="Using harness folder ${harness.dir}"/>
	
    <condition property="isWindows">
        <os family="windows" />
    </condition>

    <condition property="isMac">
        <os family="mac" />
    </condition>

	<!-- Build both windows and mac on a mac and only windows on a windows -->
    <target name="build-all" depends="clean, build-zip, build-mac">
        <echo message="Build completed. The files are available in the 'dist' folder."/>
    </target>

    <target name="build-launchers" depends="suite.build-launchers">
        <!-- Replace the icon for the Windows launcher exe. -->
        <antcall target="replaceWindowsLauncherIcon"/>
    </target>

    <!-- Windows-only target that replaces the icon for the launcher exe with our own icon. -->
    <target name="replaceWindowsLauncherIcon" if="isWindows" description="Replace the icon for the Windows launcher exe">
        <echo message="Replacing icon of Windows launcher executable."/>
        <exec executable="ReplaceVistaIcon.exe" resolveexecutable="true">
            <arg line="build/launcher/bin/${app.name}.exe ${app.name}.ico 0"/>
        </exec>
        <exec executable="ReplaceVistaIcon.exe" resolveexecutable="true">
            <arg line="build/launcher/bin/${app.name}.exe gephifile.ico 1"/>
        </exec>
    </target>

    <!-- Override to change Mac application icon. -->
    <target name="build-mac" depends="suite.build-mac" if="isMac" description="Build Mac OS X Application">
        <property name="nbdist-contents.dir" value="${dist.dir}/${app.name}.app/Contents"/>
        <property name="nbdist-resources.dir" value="${nbdist-contents.dir}/Resources"/>

        <!-- Replace the icns file. -->
        <delete file="${nbdist-resources.dir}/${app.name}.icns"/>
        <copy tofile="${nbdist-resources.dir}/${app.name}.icns" file="${app.name}.icns" />

        <!-- Unzip Netbeans Platform Localization JARs -->
        <antcall target="merge-l10n-mac"/>

        <delete file="${nbdist-contents.dir}/Info.plist"/>
        <copy tofile="${nbdist-contents.dir}/Info.plist" file="nbproject/Info.plist" />
    </target>

    <!-- Override to add localization JARs. -->
    <target name="build-zip" depends="suite.build-zip" description="Replace ZIP target">
        <!-- Unzip Netbeans Platform Localization JARs -->
        <antcall target="merge-l10n-zip"/>
    </target>

    <target name="javadoc">
        <javadoc destdir="dist/apiindex" windowtitle="Gephi API Index" encoding="UTF-8" charset="UTF-8" stylesheetfile="stylesheet.css"  packagenames="org.gephi.**.api,org.gephi.**.spi.*,org.gephi.data.*,org.gephi.utils.progress,org.gephi.preview.types" overview="overview.html"  classpath="build/public-package-jars/org-openide-util-lookup.jar">
            <sourcepath>
                <pathelement path="AttributesAPI/src"/>
                <pathelement path="ClusteringAPI/src"/>
                <pathelement path="DataLaboratoryAPI/src"/>
                <pathelement path="DynamicAPI/src"/>
                <pathelement path="ExportAPI/src"/>
                <pathelement path="FiltersAPI/src"/>
                <pathelement path="GeneratorAPI/src"/>
                <pathelement path="GraphAPI/src"/>
                <pathelement path="ImportAPI/src"/>
                <pathelement path="LayoutAPI/src"/>
                <pathelement path="LongTaskAPI/src"/>
                <pathelement path="PartitionAPI/src"/>
                <pathelement path="PerspectiveAPI/src"/>
                <pathelement path="PreviewAPI/src"/>
                <pathelement path="ProjectAPI/src"/>
                <pathelement path="RankingAPI/src"/>
                <pathelement path="RankingPlugin/src"/>
                <pathelement path="StatisticsAPI/src"/>
                <pathelement path="ToolsAPI/src"/>
                <pathelement path="TimelineAPI/src"/>
            </sourcepath>
            <doctitle>Gephi 0.8 beta API Index</doctitle>
            <header>Gephi 0.8 beta Javadoc</header>
        </javadoc>
    </target>
    
    <target name="javadoc-zip" description="Javadoc zip" depends="javadoc">
        <zip destfile="dist/apiindex/gephi-javadoc.zip" basedir="dist/" update="true"/>
    </target>

    <target name="download-l10n-jars" description="Download Netbeans Platform Localization JARs on the website">
        <property name="l10n.url" value="http://netbeans.org/project_downloads/nblocalization/7.1/"/>
        <property name="l10n.file" value="nb71_platform_l10n.zip"/>
        <property name="l10n.dir" value="l10n"/>
        <get src="${l10n.url}${l10n.file}" dest="${dist.dir}" verbose="true" skipexisting="true" ignoreerrors="true"/>   
        <available file="${dist.dir}/${l10n.file}" property="l10n.exists"/>
    </target>

    <target name="unzip-l10n" depends="download-l10n-jars" description="Unzip Netbeans Platform Localization JARs" if="l10n.exists">
        <unzip src="${dist.dir}/${l10n.file}" dest="${dist.dir}/${l10n.dir}/${app.name}"/>
    </target>
    
    <target name="merge-l10n-zip" depends="unzip-l10n" description="Merge Localization JARs on ZIP distribution" if="l10n.exists">
        <zip destfile="${dist.dir}/${app.name}.zip" basedir="${dist.dir}/${l10n.dir}" update="true"/>
        <antcall target="clean-l10n"/>
    </target>

    <target name="merge-l10n-mac" depends="unzip-l10n" description="Merge Localization JARs on MAC distribution" if="l10n.exists">
        <copy todir="${dist.dir}/${app.name}.app/Contents/Resources">
            <fileset dir="${dist.dir}/${l10n.dir}"/>
        </copy>
        <antcall target="clean-l10n"/>
    </target>

    <target name="clean-l10n" description="Clean l10n targets files and directories">
        <delete dir="${dist.dir}/${l10n.dir}" />
        <delete file="${dist.dir}/${l10n.file}"/>
    </target>

    <target name="clean-toolkit" description="Clean Toolkit dir">
        <delete failonerror="false" includeemptydirs="true">
            <fileset dir="toolkit"/>
        </delete>
    </target>

	<target name="release-toolkit"  depends="toolkit, toolkit-javadoc" description="Release Toolkit">
		<property name="toolkit.dir" value="toolkit"/>
 		<property name="demos.url" value="https://github.com/gephi/gephi-toolkit-demos/zipball/master"/>
        <property name="demos.file" value="toolkit-demos"/>
        <get src="${demos.url}" dest="${toolkit.dir}" verbose="true" skipexisting="true" ignoreerrors="true"/>
		<delete dir="${toolkit.dir}/${demos.file}"/>
		<unzip src="${toolkit.dir}/master" dest="${toolkit.dir}/${demos.file}"/>
		<path id="demos_folder_name">
			<dirset dir="${toolkit.dir}/${demos.file}/">
		    	<include name="gephi-*"/>
			</dirset>
		</path>
		<property name="demos-folder-name" refid="demos_folder_name" />
		<move file="${demos-folder-name}" tofile="${toolkit.dir}/${demos.file}" />
		<delete dir="${demos-folder-name}"/>
		<copy tofile="${toolkit.dir}/${demos.file}/lib/gephi-toolkit.jar" file="${toolkit.dir}/gephi-toolkit.jar" />
		<copy tofile="${toolkit.dir}/${demos.file}/lib/toolkit-javadoc.zip" file="${toolkit.dir}/toolkit-javadoc.zip" />
		<delete file="${toolkit.dir}/master"/>
		<zip destfile="${toolkit.dir}/gephi-toolkit.zip" basedir="${toolkit.dir}"
		       includes="gephi-toolkit.jar,toolkit-demos/**,toolkit-javadoc.zip"
		  />
    </target>

    <target name="toolkit" depends="clean-toolkit,build,build-launchers" description="Build Gephi Toolkit JAR">

        <property name="build.dir" value="${basedir}/build/cluster/modules"/>
        <property name="libs.dir" value="${basedir}/build/cluster/modules/ext"/>
        <property name="toolkit.jar.name" value="gephi-toolkit"/>
        <property name="toolkit.dir" value="${basedir}/toolkit"/>
        <property name="toolkit.jar" value="${toolkit.dir}/${toolkit.jar.name}.jar"/>
        <property name="platform.dir" value="${toolkit.dir}/platform"/>
        <mkdir dir="${toolkit.dir}"/>

        <echo message="Packaging ${app.name} into a single JAR at ${toolkit.jar}"/>

        <subant genericantfile="${harness.dir}/suite.xml" target="copy-cluster" inheritrefs="true">
            <property name="dest.dir" value="${toolkit.dir}"/>
            <property name="nbexec.dir" value="${toolkit.dir}"/>
            <property name="build.dir" value="${toolkit.dir}"/>
            <resources refid="zip.platform.clusters"/>
        </subant>

        <property name="toolkit.tempdir" value="${toolkit.dir}/${toolkit.jar.name}"/>
        <mkdir dir="${toolkit.tempdir}"/>
        <property name="toolkit.platformdir" value="${platform.dir}"/>
        <copy file="${toolkit.platformdir}/core/core.jar" tofile="${toolkit.tempdir}/core-netbeans.jar"/>
        <copy file="${toolkit.platformdir}/core/org-openide-filesystems.jar" todir="${toolkit.tempdir}"/>
        <copy file="${toolkit.platformdir}/lib/org-openide-util.jar" todir="${toolkit.tempdir}"/>
        <copy file="${toolkit.platformdir}/lib/org-openide-util-lookup.jar" todir="${toolkit.tempdir}"/>
        <copy file="${toolkit.platformdir}/lib/org-openide-modules.jar" todir="${toolkit.tempdir}"/>
        <copy todir="${toolkit.tempdir}">
            <fileset dir="${toolkit.platformdir}/modules">
                <include name="org-openide-nodes.jar"/>
                <include name="org-netbeans-modules-masterfs.jar"/>
                <include name="org-openide-dialogs.jar"/>
                <include name="org-netbeans-modules-queries.jar"/>
            </fileset>
        </copy>
        <copy todir="${toolkit.tempdir}">
            <fileset dir="${toolkit.platformdir}/modules/ext/">
                <include name="jna-*.jar"/>
            </fileset>
        </copy>
        <copy todir="${toolkit.tempdir}">
            <fileset dir="${build.dir}">
                <include name="org-gephi-algorithms.jar"/>
                <include name="org-gephi-data-attributes.jar"/>
                <include name="org-gephi-data-attributes-api.jar"/>
                <include name="org-gephi-io-exporter-preview.jar"/>
                <include name="org-gephi-filters.jar"/>
                <include name="org-gephi-filters-api.jar"/>
                <include name="org-gephi-filters-plugin.jar"/>
                <include name="org-gephi-graph-api.jar"/>
                <include name="org-gephi-graph-dhns.jar"/>
                <include name="org-gephi-io-database-drivers.jar"/>
                <include name="org-gephi-utils-collection.jar"/>
                <include name="org-gephi-io-exporter-api.jar"/>
                <include name="org-gephi-io-exporter-plugin.jar"/>
                <include name="org-gephi-io-importer-api.jar"/>
                <include name="org-gephi-io-importer-plugin.jar"/>
                <include name="org-gephi-io-processor-plugin.jar"/>
                <include name="org-gephi-layout-api.jar"/>
                <include name="org-gephi-layout-plugin.jar"/>
                <include name="org-gephi-preview-api.jar"/>
                <include name="org-gephi-preview-plugin.jar"/>
                <include name="org-gephi-project-api.jar"/>
                <include name="org-gephi-statistics-api.jar"/>
                <include name="org-gephi-statistics-plugin.jar"/>
                <include name="org-gephi-timeline.jar"/>
                <include name="org-gephi-dynamic-api.jar"/>
                <include name="org-gephi-dynamic.jar"/>
                <include name="org-gephi-utils.jar"/>
                <include name="org-gephi-utils-longtask.jar" />
                <include name="org-gephi-ranking-api.jar"/>
                <include name="org-gephi-ranking-plugin.jar"/>
                <include name="org-gephi-partition-api.jar"/>
                <include name="org-gephi-partition-plugin.jar"/>
                <include name="org-gephi-io-generator-api.jar"/>
                <include name="org-gephi-io-generator-plugin.jar"/>
                <include name="org-gephi-datalab-api.jar"/>
                <include name="org-gephi-visualization-api.jar"/>
            </fileset>
        </copy>
        <copy todir="${toolkit.tempdir}">
            <fileset dir="${libs.dir}">
                <include name="batik*.jar"/>
                <include name="bzip2*.jar"/>
                <include name="core.jar"/><!-- Processing -->
                <include name="iText*.jar"/>
                <include name="jcommon*.jar"/>
                <include name="commons*.jar"/>
                <include name="jfreechart*.jar"/>
                <include name="joda-time*.jar"/>
                <include name="mysql-connector*.jar"/>
                <include name="postgresql*.jar"/>
                <include name="sqljdbc*.jar"/>
                <include name="sqlite*.jar"/>
                <include name="teradata*.jar"/>
                <include name="google-collect*.jar"/>
                <include name="stax-utils.jar"/>
                <include name="trove*.jar"/>
                <include name="xml-apis-ext*.jar"/>
                <include name="javacsv*.jar"/>
            </fileset>
        </copy>

        <jar destfile="${toolkit.dir}/temp_final.jar" filesetmanifest="merge" duplicate="preserve">
            <zipgroupfileset dir="${toolkit.tempdir}" includes="*.jar"/>
            
            <!-- Next service declarations fix problem of having service providers in different modules (duplicated files) -->
            <service type="org.openide.filesystems.URLMapper">
                <provider classname="org.netbeans.modules.masterfs.MasterURLMapper"/>
                <provider classname="org.netbeans.modules.openide.filesystems.DefaultURLMapperProxy"/>
                <provider classname="org.openide.filesystems.MemoryFileSystem$Mapper"/>
                <provider classname="org.netbeans.core.startup.layers.ArchiveURLMapper"/>
            </service>
            
            <service type="javax.annotation.processing.Processor">
                <provider classname="org.netbeans.modules.openide.filesystems.CleaningAnnotationProcessor"/>
                <provider classname="org.netbeans.modules.openide.util.NbBundleProcessor"/>
                <provider classname="org.netbeans.modules.openide.util.URLStreamHandlerRegistrationProcessor"/>
                <provider classname="org.netbeans.modules.openide.util.ServiceProviderProcessor"/>
            </service>
            
            <service type="java.sql.Driver">
                <provider classname="com.mysql.jdbc.Driver"/>
                <provider classname="org.postgresql.Driver"/>
                <provider classname="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
                <provider classname="org.sqlite.JDBC"/>
                <provider classname="com.teradata.jdbc.TeraDriver"/>
            </service>
            
            <service type="org.gephi.project.spi.WorkspacePersistenceProvider">
                <provider classname="org.gephi.data.attributes.serialization.AttributeModelPersistenceProvider"/>
                <provider classname="org.gephi.graph.dhns.DhnsPersistenceProvider"/>
                <provider classname="org.gephi.graph.dhns.DataPersistenceProvider"/>
                <provider classname="org.gephi.data.attributes.serialization.AttributeRowPersistenceProvider"/>
                <provider classname="org.gephi.dynamic.DynamicModelPersistenceProvider"/>
                <provider classname="org.gephi.filters.FilterModelPersistenceProvider"/>
                <provider classname="org.gephi.layout.LayoutModelPersistenceProvider"/>
                <provider classname="org.gephi.partition.impl.PartitionModelPersistenceProvider"/>
                <provider classname="org.gephi.statistics.StatisticsPersistenceProvider"/>
                <provider classname="org.gephi.preview.PreviewPersistenceProvider"/>
            </service>
            
            <service type="org.gephi.project.spi.WorkspaceDuplicateProvider">
                <provider classname="org.gephi.data.attributes.AttributeModelDuplicateProvider"/>
                <provider classname="org.gephi.graph.dhns.DhnsDuplicateProvider"/>
                <provider classname="org.gephi.dynamic.DynamicModelDuplicateProvider"/>
                <provider classname="org.gephi.preview.PreviewWorkspaceDuplicateProvider"/>
            </service>
                
            <!-- These are services from core.startup modules. We disable them because they deal with the startup only -->
            <service type="org.openide.util.Lookup" provider="" />
            <service type="org.openide.filesystems.Repository" provider="" />
            <service type="org.openide.util.NbPreferences$Provider" provider="" />
            <service type="org.netbeans.modules.masterfs.watcher.Watcher" provider="" />
            <service type="org.netbeans.modules.masterfs.providers.AnnotationProvider" provider="" />
            
            <manifest>
            </manifest>
        </jar>

        <zip destfile="${toolkit.jar}">
            <zipfileset src="${toolkit.dir}/temp_final.jar"
            excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA,
            org/netbeans/modules/masterfs/watcher/Watcher*,
            META-INF/services/org.netbeans.modules.masterfs.watcher.Watcher"/>
        </zip>

        <delete file="${toolkit.dir}/temp_final.jar"/>
        <delete dir="${platform.dir}"/>

    </target>

    <target name="toolkit-javadoc">
        <javadoc destdir="${basedir}/toolkit/doc" windowtitle="Gephi Toolkit API Index" encoding="UTF-8" charset="UTF-8" stylesheetfile="stylesheet.css"  packagenames="org.gephi.*" overview="overview.html" classpath="build/public-package-jars/org-openide-util-lookup.jar">
            <sourcepath>
                <pathelement path="Algorithms/src"/>
                <pathelement path="AttributesAPI/src"/>
                <pathelement path="PreviewExport/src"/>
                <pathelement path="FiltersAPI/src"/>
                <pathelement path="FiltersPlugin/src"/>
                <pathelement path="GraphAPI/src"/>
                <pathelement path="DBDrivers/src"/>
                <pathelement path="ExportAPI/src"/>
                <pathelement path="ExportPlugin/src"/>
                <pathelement path="ImportAPI/src"/>
                <pathelement path="ImportPlugin/src"/>
                <pathelement path="ProcessorPlugin/src"/>
                <pathelement path="LayoutAPI/src"/>
                <pathelement path="LayoutPlugin/src"/>
                <pathelement path="PreviewAPI/src"/>
                <pathelement path="PreviewPlugin/src"/>
                <pathelement path="ProjectAPI/src"/>
                <pathelement path="StatisticsAPI/src"/>
                <pathelement path="StatisticsPlugin/src"/>
                <pathelement path="DynamicAPI/src"/>
                <pathelement path="Utils/src"/>
                <pathelement path="LongTaskAPI/src"/>
                <pathelement path="RankingAPI/src"/>
                <pathelement path="PartitionAPI/src"/>
                <pathelement path="PartitionPlugin/src"/>
                <pathelement path="GeneratorAPI/src"/>
                <pathelement path="GeneratorPlugin/src"/>
                <pathelement path="DataLaboratoryAPI/src"/>
                <pathelement path="TimelineAPI/src"/>
            </sourcepath>
            <doctitle>Gephi Toolkit Javadoc</doctitle>
            <header>Gephi Toolkit Javadoc</header>
        </javadoc>
        <zip destfile="${basedir}/toolkit/toolkit-javadoc.zip" basedir="${basedir}/toolkit/doc">
        </zip>
    </target>
</project>
